package com.ruoyi.project.digital.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;

import com.ruoyi.project.digital.config.DataConstans;
import com.ruoyi.project.digital.domain.Apply;
import com.ruoyi.project.digital.domain.vo.ApplyExprotVo;
import com.ruoyi.project.digital.domain.vo.ApplyPayInfoVo;
import com.ruoyi.project.digital.mapper.ApplyMapper;
import com.ruoyi.project.digital.service.IApplyService;
import com.ruoyi.project.system.service.ISysDictDataService;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 打印申请Service业务层处理
 *
 * @author ruoyi
 * @date 2020-12-17
 */
@Service
public class ApplyServiceImpl implements IApplyService
{
    @Autowired
    private ApplyMapper applyMapper;
    @Autowired
    private ISysDictDataService dictDataService;
    /**
     * 查询打印申请
     *
     * @param id 打印申请ID
     * @return 打印申请
     */
    @Override
    public Apply selectApplyById(Long id)
    {
        Apply apply= applyMapper.selectApplyById(id);
        String label= dictDataService.selectDictLabel(DataConstans.PRINT_TYPE,apply.getPrintType());
        apply.setPrintType(label);
        return apply;
    }

    /**
     * 查询打印申请列表
     *
     * @param apply 打印申请
     * @return 打印申请
     */
    @Override
    public List<Apply> selectApplyList(Apply apply)
    {
        return applyMapper.selectApplyList(apply);
    }


    /**
     * 查询打印申请列表
     *
     * @param apply 打印申请
     * @return 打印申请
     */
    @Override
    public List<ApplyPayInfoVo> selectApplyList2(Apply apply)
    {
        return applyMapper.selectApplyList2(apply);
    }

    /**
     * 新增打印申请
     *
     * @param apply 打印申请
     * @return 结果
     */
    @Override
    public int insertApply(Apply apply)
    {
        apply.setCreateTime(DateUtils.getNowDate());
        return applyMapper.insertApply(apply);
    }

    /**
     * 修改打印申请
     *
     * @param apply 打印申请
     * @return 结果
     */
    @Override
    public int updateApply(Apply apply)
    {
        apply.setUpdateTime(DateUtils.getNowDate());
        return applyMapper.updateApply(apply);
    }

    /**
     * 批量删除打印申请
     *
     * @param ids 需要删除的打印申请ID
     * @return 结果
     */
    @Override
    public int deleteApplyByIds(Long[] ids)
    {
        return applyMapper.deleteApplyByIds(ids);
    }

    /**
     * 删除打印申请信息
     *
     * @param id 打印申请ID
     * @return 结果
     */
    @Override
    public int deleteApplyById(Long id)
    {
        return applyMapper.deleteApplyById(id);
    }

    @Override
    public List<ApplyExprotVo> coverExportList(List<Apply> list) {
        List<ApplyExprotVo> voList=new ArrayList<>();
        for(Apply apply:list){
            ApplyExprotVo vo=new ApplyExprotVo();
            BeanUtils.copyProperties(apply,vo);
            vo.setAddress(apply.getProvince()+apply.getCity()+apply.getCounty()+apply.getAddressDetails());
            voList.add(vo);
        }
        return voList;
    }
}
